//
// Created by buk on 8/28/24.
//

#ifndef WEB_SERVER_H
#define WEB_SERVER_H

#include "../../../thirdparty/Simple-Web-Server/client_http.hpp"
#include "../../../thirdparty/Simple-Web-Server/server_http.hpp"
#include "../base/messages.hpp"

using HttpServer = SimpleWeb::Server<SimpleWeb::HTTP>;

namespace ai::facial_recognition {

    class WebServer {
    public:
        WebServer();
        explicit WebServer(int port);
        ~WebServer();

        void start();
        void stop();

        void subscribeRequest(const RequestSignalType::slot_type &request_slot);
    private:
        std::jthread jthread_server_;
        HttpServer server;
        int server_port;
        std::string web_root = "wwwroot";
        RequestSignalType request_signal_;

        void init();
        void writeResponse(std::shared_ptr<HttpServer::Response> response, std::shared_ptr<BaseMessage> msg);


    };
}


#endif //WEB_SERVER_H
